package team.archai.nexus.flow.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 报表设计器资源文件注册配置类
 *
 * @author lishibin
 * @version 2025-04-09
 * @since 1.8
 **/
public class FlowDesignerWebConfigurerAdapter implements WebMvcConfigurer {


    /**
     * 预留字段
     */
    private final String baseUrl;


    public FlowDesignerWebConfigurerAdapter(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String baseUrl = StringUtils.trimTrailingCharacter(this.baseUrl, '/');
        registry.
                addResourceHandler(baseUrl + "/flow-designer/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/flow-designer/")
                .resourceChain(false);
    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController(baseUrl + "/flow-designer/")
                .setViewName("forward:" + baseUrl + "/flow-designer/index.html");
    }
}
